package com.test.reggieadmin.model.fragment.cpgl;

import com.test.reggieadmin.base.BaseObserver;
import com.test.reggieadmin.base.BasePresenter;
import com.test.reggieadmin.bean.BaseBean;
import com.test.reggieadmin.bean.DishPageBean;

import java.util.Map;

public class CpglPrensenter extends BasePresenter<CpglView> {
    public CpglPrensenter(CpglView baseView) {
        super(baseView);
    }

    /**
     * 菜品信息分页查询
     *
     * @param page
     * @param pageSize
     * @param name
     * @param type
     */
    public void dishPage(int page, int pageSize, String name, int type) {
        addDisposable(apiServer.dishPage(page, pageSize, name), new BaseObserver<DishPageBean>() {
            @Override
            public void onSuccess(DishPageBean bean) {
                baseView.dishPageSuccess(bean, type);
            }

            @Override
            public void onError(String msg) {
                baseView.dishPageError(msg);
            }
        });
    }

    /**
     * 修改菜品
     *
     * @param map
     */
    public void updateDish(Map<String, Object> map) {
        addDisposable(apiServer.updateDish(map), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.updateDishSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 删除菜品
     *
     * @param ids
     */
    public void deleteDish(String ids) {
        addDisposable(apiServer.deleteDish(ids), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.deleteDishSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }
}
